package jc223504;
/**
 * @(#)KookWai_A1.java
 *
 * KookWai_A1 application
 *
 * @Lock Kook Wai
 * @version 1.00 2011/3/24
 */

import java.util.ArrayList;

/**
* Call Project Model class and setup 2 dimensional array
*/
public class GridView
{
    char[][] cell;
    ProjModel pm;
    int gridSize;


    public GridView()
    {
    }

    public GridView(ProjModel pm)
    {
        this.pm = pm;
        cell = new char[pm.getGridSize()][pm.getGridSize()];
        gridSize = pm.getGridSize();

    }

    	/**
     	* Setup grid
     	*/

    public void initGrid()
    {
         //initialise cell with '?'
        for(int i=0; i<gridSize; i++)
        {
            for(int j=0; j<gridSize; j++)
            {
                cell[i][j] = '?';
            }
        }

        //buildHorLane();
        //buildVerLane();
        //buildCars();
    }

    public void showGrid()
    {
        for(int i=0; i<gridSize; i++)
        {
            for(int j=0; j<gridSize; j++)
            {
                System.out.print(cell[i][j]);
            }
             System.out.println();
        }
    }

    /**
     * Build Horizontal lanes
     */

    public void buildHorLane(int hor)
    {
        int gs = pm.getGridSize();
        int middleHor = pm.getMiddleHor();

        for(int i = 0; i<hor; i++)
        {
        	for(int j = 0; j<gs; j++)
        	{
        		cell[middleHor] [j]=' ';
        	}
        	middleHor++;
        }


    }

    /**
     * Build Vertical lanes
     */

    public void buildVerLane(int ver)
    {
       int gs = pm.getGridSize();
       int middleVer = pm.getMiddleVer();

       for(int i = 0; i<ver; i++)
       {
       	for(int j = 0; j<gs; j++)
       	{
       		cell[j][middleVer]= ' ';
       	}
       	middleVer++;
       }
    }

    /**
     * Build Cars
     */

    public void buildCars(int X, int Y)
    {
    	cell[X][Y]='c';
    }

    /**
     * Remove cars to move to new position
     */

    public void removeCars(int X, int Y)
    {
    	cell[X][Y]=' ';
    }

    /**
     * Build Traffic lights, R = red and G = Green
     */

    public void buildTrafficLights(int X, int Y, boolean light)
    {
    	if(light == false)
    	{
    		cell[X][Y]='R';
    	}
    	else
    	{
    		cell[X][Y]='G';
    	}
    }

    /**
     * Set traffic light position X axis
     */

    public int setTrafficLightXPos(int middle, int lane)
    {
    	int X = middle + lane;
    	return X;
    }

     /**
     * Set traffic light position Y axis
     */

    public int setTrafficLightYPos(int middle, int lane)
    {
    	int Y = middle + lane;
    	return Y;
    }
/*
    public void buildCars()
    {
         int middle = gridSize / 2;  //gridSize =20; middle = 10
         carArray.add(new Car(middle, middle));

         Car c1 = carArray.get(0);
         cell[c1.getXPos()][c1.getYPos()] = 'c';
    }
   */
}
